package top.codedance.iotp.loadblance.algorithm;

import top.codedance.iotp.loadblance.entiy.RegistyUri;

import java.util.*;

public class Weight extends Adapter {
    @Override
    public String execute(List<RegistyUri> registyUris, Func<String> func) {
        Set<RegistyUri> sorts = new TreeSet<>((i1, i2) -> i1.getWeight() > i2.getWeight() ? 1 : -1);
        for(RegistyUri ru : registyUris){
            sorts.add(ru);
        }
        String result = null;
        for (RegistyUri ru : sorts){
            result = func.run(ru.getUrl());
            if(result != null){
                break;
            }
        }
        return result;
    }
}
